package com.planet.api;

import com.planet.facade.AssessmentUserBiz;
import com.planet.query.AssessmentUserQuery;
import com.planet.utils.global.ExceptionHandle;
import com.planet.utils.global.Result;
import com.planet.utils.global.ResultUtil;
import com.planet.vo.AssessmentUserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by jiayazi on 17/11/14.
 */

@Api("已督办和为督办")
@RestController
@RequestMapping("nb/api/duban")
public class DubanAPI {

    @Autowired
    AssessmentUserBiz assessmentUserBiz;
    @Autowired
    private ExceptionHandle exceptionHandle;



    /**
     * 督办
     * @param
     * @return
     */
    @GetMapping("/assess")
    @ApiOperation(value = "督办")
    public Result assess(@ApiParam("assessmentUserQuery") AssessmentUserQuery assessmentUserQuery){
        //committee,address,assess_require,handle_time,phone

        assessmentUserQuery.setAsssee_type(1);
        //默认结果是成功的
        Result result = ResultUtil.success();
        try {
            boolean state = assessmentUserBiz.assess(assessmentUserQuery);
            result = ResultUtil.success(state);
        }catch (Exception e){
            //调用异常工具类，统一处理异常
            result =  exceptionHandle.exceptionGet(e);
        }
        return result;
    }



    /**
     * 获取被督办信息
     * @param
     * @return
     */
    @GetMapping("/getAssessInfoWithPhone")
    @ApiOperation(value = "获取被督办信息")
    public Result getAssessInfoWithPhone(@ApiParam("phone") @RequestParam String phone){

        //默认结果是成功的
        Result result = ResultUtil.success();
       try {
            AssessmentUserVO assessmentUserVO = assessmentUserBiz.selectByPhone(phone);
            result = ResultUtil.success(assessmentUserVO);
        }catch (Exception e){
            //调用异常工具类，统一处理异常
            result =  exceptionHandle.exceptionGet(e);
        }
        return result;
    }




    /**
     * 已经考核列表
     * @param
     * @return
     */
    @GetMapping("/haveCheck")
    @ApiOperation(value = "已经考核列表")
    public Result haveCheck(@ApiParam("pageSize") @RequestParam String pageSize,
                            @ApiParam("pageIndex") @RequestParam String pageIndex){

        //默认结果是成功的
        Result result = ResultUtil.success();
        try {
            List<AssessmentUserVO> assessmentUserVOS = assessmentUserBiz.selectHaveAssessList();
            result =  ResultUtil.success(assessmentUserVOS);

        }catch (Exception e){
            //调用异常工具类，统一处理异常
            result =  exceptionHandle.exceptionGet(e);
        }
        return result;
    }


    /**
     * 未考核列表
     * @param
     * @return
     */
    @GetMapping("/haveNoCheck")
    @ApiOperation(value = "未考核列表")
    public Result haveNoCheck(@ApiParam("pageSize") @RequestParam String pageSize,
                              @ApiParam("pageIndex") @RequestParam String pageIndex){

        //默认结果是成功的
        Result result = ResultUtil.success();
        try {
            List<AssessmentUserVO> assessmentUserVOS = assessmentUserBiz.selectNoHaveAssessList();
            result =  ResultUtil.success(assessmentUserVOS);

        }catch (Exception e){
            //调用异常工具类，统一处理异常
            result =  exceptionHandle.exceptionGet(e);
        }
        return result;
    }
}
